#ifndef __GAME_YML_H__
#define __GAME_YML_H__

#include "game_def.h"
#include <string.h>
#include "ryml_std.hpp" // optional header. BUT when used, needs to be included BEFORE ryml.hpp
#include "ryml.hpp"
#include "c4/format.hpp"
#include "c4/charconv.hpp"

class CGameYML{
protected:
  static void trace(const ryml::ConstNodeRef &node);
  ryml::Tree _tree;


  void _trace();
public:
  static BOOL getNode(ryml::NodeRef &tree ,const char *path, ryml::NodeRef &dest);
  BOOL getNode(const char *path, ryml::NodeRef &dest);
  BOOL load( const char* filename);
  BOOL save(const char* dest);
  BOOL parse(const char* buf);
  // std::string dump();
  std::string getString(const char* key,const char* _default);
  std::string getString(const char* key,const std::string& _default);
  size_t getString(char* dest, size_t dest_max, const char* key,const char* _default);
  UINT32 getUINT32(const char* key,UINT32 _default);
  UINT32 getUINT32(const char* key);
  void trace(FILE* p){
    ryml::emit_yaml(_tree, p);
  };
  ryml::NodeRef getRoot(){
    return _tree.rootref();
  };
};

#endif
